<?php
class MyApp_Base_AppObject extends Ethna_AppObject
{
	/**
	 *
	 *  DBオブジェクト(read only/read-write)を取得する
	 *
	 *  @override
	 *
	 *  @access protected
	 *  @return array   array('ro' => {read only db object}, 'rw' => {read-write db object})
	 */
	function _getDBList()
	{
		$db_key_rw = '';
		$db_key_ro = 'r';
		if($this->db_prefix){
			$db_key_rw = $this->db_prefix;
			$db_key_ro = $this->db_prefix .'_r';
		}
		
		$r = array('ro' => null, 'rw' => null);

		$db_list = $this->backend->getDBList();
		if (Ethna::isError($db_list)) {
			return $r;
		}
		foreach ($db_list as $elt) {
			if ($elt['key'] != $db_key_rw && $elt['key'] != $db_key_ro){
				continue;
			}
			$varname = $elt['varname'];

			$this->$varname =& $elt['db'];

			if ($elt['type'] == DB_TYPE_RW) {
				$r['rw'] =& $elt['db'];
			} else if ($elt['type'] == DB_TYPE_RO) {
				$r['ro'] =& $elt['db'];
			}
		}
		if ($r['ro'] == null && $r['rw'] != null) {
			$r['ro'] =& $r['rw'];
		}

		return $r;
	}
}